package com.hqyj.fj.javaSpringBoot.modules.account.dao;

import com.hqyj.fj.javaSpringBoot.modules.account.entity.Resource;
import org.apache.ibatis.annotations.*;

import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ResourceDaoR {
    @Select("select * from account_resource where id = #{id}")
    @Results(id="resourceResult", value={
            @Result(column="id", property="id"),
            @Result(column="id",property="roles",
                    javaType= List.class,
                    many=@Many(select="com.hqyj.fj.javaSpringBoot.modules.account.dao.RoleDao.getRolesByResourceId"))
    })
    Resource getResourceById(int id);

    @Select("select * from account_resource ar left join account_role_resource arr on ar.id = arr.resource_id "
            + "where arr.role_id = #{roleId}")
    List<Resource> getResourcesByRoleId(int roleId);

}
